<?php
namespace Home\Model;
use Think\Model\RelationModel;
/**
 * 推荐用户注册收入
 * @author Administrator
 *
 */
class RecommedIncomeModel extends  RelationModel 
{
    
    protected $_auto = array (
        array('createdate','date',1,'function',array('Y-m-d H:i:s')),
    );
    
    protected $_link = array(
        'User'=>array(
            'mapping_type'=> self::BELONGS_TO,
            'mapping_name'=> 'user',
            'class_name'=> 'User',
            'foreign_key'=>'register_uid'
        ),
    );
    
    
    /**
     * 插入推荐用户注册收入记录
     * @param unknown $arry
     * @return number|unknown
     */
    public function inst($arry)
    {
        foreach ($arry as $key => $value){
            $data[$key] = $value;
        };
        $result["status"]=0;
        if (!$this->create($data)){
            $result["mess"]=$this->getError();
        }else{
            $result = $this->add(); // 写入数据到数据库
            if($result){
                $result["status"]=1;
                $result["mess"]=$result;
            }
        };
        return $result;
    }
    
    /**
     * 查询插入推荐用户注册收入记录
     * @param  $arry
     * @return 
     */
	public function getListByTime($uid,$queryTime)
	{
	    $con['uid'] =$uid;
	    if($queryTime != 9){
                $con["createdate"] = array('between', array(date('Y-m-d 00:00:00',time()-60*60*24*30*$queryTime),date('Y-m-d 23:59:59', time())));
	    };
        return $this->relation(true)->where($con)->select();
	}
	
	public function getCountByTime($uid,$queryTime)
	{
	    $con['uid'] =$uid;
	    if($queryTime != 9){
            $con["createdate"] = array('between', array(date('Y-m-d 00:00:00',time()-60*60*24*30*$queryTime),date('Y-m-d 23:59:59', time())));
	    };
	    return $this->where($con)->count();
	}
	
	
	public function getCount($arry)
	{
	    foreach ($arry as $key => $value){
	        $condition[$key] = $value;
	    };
	    return $this->where($condition)->count();
	}
}
?>